﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows.Input;
using WPFHelpers;

namespace Tourbook.Riders
{
    public class RiderCollectionViewModel : ObservableObject, IPageViewModel
    {
        #region Members & ctors

        private RiderViewModel mSelectedRider;

        public RiderCollectionViewModel()
        {
            CreateNewRiderCommand = new RelayCommand(obj => CreateNewRider(obj));
            ErrorConverter = new ErrorToStringConverter();
            Riders = new ObservableCollection<RiderViewModel>();
            // Test Data
            for (int i = 0; i < 10; ++i)
            {
                Riders.Add(new RiderViewModel() { FirstName = "Rider", LastName = i.ToString(), Email = "Test@test.de"  });
            }        
        }


        #endregion

        #region Properties & commands

        // GUI aspect
        public ObservableCollection<RiderViewModel> Riders { get; private set; }    
        public RiderViewModel SelectedRider
        {
            get
            {
                return mSelectedRider;
            }
            set
            {
                if (mSelectedRider != value)
                {
                    mSelectedRider = value;
                    OnPropertyChanged("SelectedRider");
                }
            }
        }

        public ICommand CreateNewRiderCommand{ get; private set; }
        public ErrorToStringConverter ErrorConverter { get; private set; }

        private void CreateNewRider(object obj)
        {
            RiderViewModel newRider = new RiderViewModel{LastName = "New Rider" };
            Riders.Add(newRider);
            SelectedRider = newRider;
        }

        #endregion

        #region IPageViewModel

        public string PageName
        {
            get
            {
                return "Riders";
            }
        }

        public string Content
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }

        #endregion
    }
}
